simplexml: filter addChild() result by the created element's namespace - #23599
Open
iliaal wants to merge 1 commit into
Open
simplexml: filter addChild() result by the created element's namespace#23599iliaal wants to merge 1 commit into
iliaal wants to merge 1 commit into
Conversation
addChild() built the returned SimpleXMLElement with the prefix the caller passed in, not the one the new node ended up in, so a child added through that object was filtered against the wrong namespace and was invisible by property name. Take the prefix from newnode->ns instead. The filter keys on the prefix rather than the href because node_as_zval() installs no filter at all for a prefixless namespace, and switching to href would start filtering the default-namespace case that today has none. Closes phpGH-23599
iliaal
force-pushed
the
promote/simplexml-addchild-ns
branch
from
September 6, 2026 15:08
0a411a4 to
10af2d1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SimpleXMLElement::addChild()built the returned element with the prefix the caller passed in rather than the one the new node ended up in, so a child added through that returned object was filtered against the wrong namespace and could not be reached by property name. Taking the prefix fromnewnode->nsfixes all three cases: an explicita:kidwith a matching uri, a barekidwith a uri, and a barekidunder a prefixed parent wherexmlNewChildinherits the parent's prefix.The filter keys on the prefix rather than the href deliberately.
node_as_zval()installs no filter at all when the prefix is null or empty, so switching to href matching would start filtering the default-namespace case that currently has none.